Terminal
Terminal is a conceptual combination of devices used by humans to interface with the computer. The earliest terminals where text based terminals consisting of a keyboard and a screen connected to the serial port. Overview The following image descibes a typical terminal connected to a Linux system: If the temrinal is physically remote, a modem could be used to connect it. The software part remains unchanged, the hardware part becomes as follows: Definitions and Assumptions Linux Virtual Terminal In Linux, virtual terminal is a character special device file connected to a device driver that in turn controls the terminal. Typically, there are many virtual terminals in a single system /dev/tty1 ~ /dev/tty63 all of which are handled by device driver with major number 4. There are also other character special files related to virtual terminals but handled by the device driver with major number 5. These are /dev/tty which is connected by the kernel to the virtual terminal of the calling process, and /dev/tty1 discussed in (Linux Console) below. The following image shows how each user process's in/out is connected to its respictive virtual terminal. Linux Psuedo Terminal in Linux, a pseudo-terminal, or PTY, is used to create login sessions or provide other capabilities requiring a TTY line discipline (see below), including SLIP or PPP capability, to arbitrary data-generation processes. Each PTY has a master side, named /dev/ptyp-za-e0-9a-f, and a slave side, named /dev/ttyp-za-e0-9a-f. The kernel arbitrates the use of PTYs by allowing each master side to be opened only once. Once the master side has been opened, the corresponding slave device can be used in the same manner as any TTY device. The master and slave devices are connected by the kernel, generating the equivalent of a bidirectional pipe with TTY capabilities. The following image shows how each user process's in/out is connected to the xterm process behind its respective pty: Linux Console Linux console is a pointer file that points to a virtual terminal. Earlier, it used to be a symbolic link, but now it is a character device file handled by device driver with major number 5. Its main objective is to abstract the destination of kernel log messages from the kernel function. This way, printk can send messages only to this file without needing to woory about virtual temrinals or where these messages should be sent (serial port, etc). By default, the “console” is the current virtual terminal. To select a different virtual terminal to receive messages, you can issue ioctl(TIOCLINUX) on any console device. The concole file is /dev/tty1 (previously /dev/console) and is connected by the kernel to one of the virtual terminals during boot e.g “console=tty1”. Linux Line Discipline The line discipline glues the low level device driver code with the high level generic interface routines (such as read(2), write(2) and ioctl(2)), and is responsible for implementing the semantics associated with the device. The policy is separated from the device driver so that the same serial hardware driver can be used by devices that require different data handling. For example, the standard line discipline processes the data it receives from the hardware driver and from applications writing to the device according to the requirements of a terminal on a Unix-like system. On input, it handles special characters such as the interrupt character (typically Control-C) and the erase and kill characters (typically backspace or delete, and Control-U, respectively) and, on output, it replaces all the LF characters with a CR/LF sequence. As another example, a serial port could also be used for a dial-up Internet connection using a serial modem and PPP. In this case, a PPP line discipline would be used; it would accumulate input data from the serial line into PPP input packets, delivering them to the networking stack rather than to the character device, and would transmit packets delivered to it by the networking stack on the serial line. How-To Getting Started Pitfalls